﻿using AesonPrismMonoProject.Config;
using AesonPrismMonoProject.Views.HomePage;
using Microsoft.Practices.Prism.Logging;
using Microsoft.Practices.Prism.Mvvm;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Unity;
using System.Windows;
using AesonPrismMonoProject.LocalConsole;
using AesonPrismMonoProject.Logger;
using AesonPrismMonoProject.Views.MainViews;
using AesonPrismMonoProject.Tools;

namespace AesonPrismMonoProject
{
    public class AppBootstrapper : UnityBootstrapper
    {
        private readonly AesonPrismLogger _aesontLogger = new AesonPrismLogger();
        private readonly AesonClientConsole _clientConsole = new AesonClientConsole();

        public IRegionManager RegionManager
        {
            get
            {
                return this.Container.Resolve<IRegionManager>();
            }
        }

        protected override DependencyObject CreateShell()
        {
            return Container.Resolve<MainWindows>();
        }

        protected override void InitializeShell()
        {
            base.InitializeShell();
            Application.Current.MainWindow = (Window)Shell;
            Application.Current.MainWindow.Show();


        }
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
            ViewModelLocationProvider.SetDefaultViewModelFactory((t) => Container.Resolve(t));
            this.Container.RegisterInstance<AesonPrismLogger>(this._aesontLogger);
            this.Container.RegisterInstance<AesonClientConsole>(this._clientConsole);
        }

        protected override void InitializeModules()
        {
            base.InitializeModules();

            this.RegionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(HomePage));
        }

        protected override void ConfigureModuleCatalog()
        {
            PrismModuleManager.LoadModules(ModuleCatalog);
        }

        protected override ILoggerFacade CreateLogger()
        {
            return this._aesontLogger;
        }
    }
}
